package com.quasar.hpatient.bean.comm_album;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import lib.quasar.context.BaseConstant;
import lib.quasar.widget.photo.PhotoModel;

/**
 * description: 相册图片信息
 * created by kalu on 2018/4/19 9:23
 */
public class AlbumPhotoBean implements PhotoModel, Parcelable {

    public static final Creator<AlbumPhotoBean> CREATOR = new Creator<AlbumPhotoBean>() {
        @Override
        public AlbumPhotoBean createFromParcel(Parcel in) {
            return new AlbumPhotoBean(in);
        }

        @Override
        public AlbumPhotoBean[] newArray(int size) {
            return new AlbumPhotoBean[size];
        }
    };
    private int width;
    private int height;
    private long size;
    private boolean check = false;
    private String local_name = "";
    private String picture = "";

    public AlbumPhotoBean() {
    }

    protected AlbumPhotoBean(Parcel in) {
        width = in.readInt();
        height = in.readInt();
        size = in.readLong();
        check = in.readByte() != 0;
        local_name = in.readString();
        picture = in.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(width);
        dest.writeInt(height);
        dest.writeLong(size);
        dest.writeByte((byte) (check ? 1 : 0));
        dest.writeString(local_name);
        dest.writeString(picture);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public boolean isCheck() {
        return check;
    }

    public void setCheck(boolean check) {
        this.check = check;
    }

    public String getLocal_name() {
        return local_name;
    }

    public void setLocal_name(String local_name) {
        this.local_name = local_name;
    }

    public String getPicture() {
        return picture;
    }

    public void setPicture(String picture) {
        this.picture = picture;
    }

    public int getRatio() {
        if (size <= 3686400) {
            return 100;
        } else {
            return 50;
        }
    }

    // 200KB不需要压缩
    public boolean needCompress() {
        return size > 204800;
    }

    public int calcuWidth() {

        int temp = width;

        while (temp > 1280) {
            temp = temp / 2;
        }
        return temp;
    }

    public int calcuHeight() {

        int temp = height;

        while (temp > 1280) {
            temp = temp / 2;
        }
        return temp;
    }

    @Override
    public String getUrl() {
        if (!TextUtils.isEmpty(picture) && picture.endsWith(".jpg")) {
            return BaseConstant.API_URL + picture;
        } else {
            return picture;
        }
    }

    @Override
    public String getUrlLittle() {
        if (!TextUtils.isEmpty(picture) && picture.endsWith(".jpg")) {
            return BaseConstant.API_URL + picture;
        } else {
            return picture;
        }
    }

    public boolean isAdd() {
        return !TextUtils.isEmpty(picture) && !picture.endsWith(".jpg");
    }

    @Override
    public String toString() {
        return "AlbumPhotoBean{" +
                "width=" + width +
                ", height=" + height +
                ", size=" + size +
                ", check=" + check +
                ", local_name='" + local_name + '\'' +
                ", picture='" + picture + '\'' +
                '}';
    }
}
